package com.keyancompany.zhongbaopingtai.activity;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;

import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.adapter.IFragmentPagerAdapter;
import com.keyancompany.zhongbaopingtai.fragment.MyCircleFragment;
import com.keyancompany.zhongbaopingtai.utils.IntentUtils;
import com.keyancompany.zhongbaopingtai.utils.T;
import com.keyancompany.zhongbaopingtai.weight.CustomEditText;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.BindString;
import butterknife.OnClick;

/**
 * 我的圈子
 */
public class MyCircleActivity extends BaseActivity {

    @BindString(R.string.my_circle_text)
    String title;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.tabLayout)
    TabLayout tabLayout;
    @Bind(R.id.complaint_viewpager)
    ViewPager complaintViewpager;
    @Bind(R.id.filter_edit)
    CustomEditText filterEdit;
    @Bind(R.id.send_message)
    ImageView search;


    @Override
    protected int getContentViewId() {
        return R.layout.activity_my_circle;
    }

    @Override
    protected int getMenuId() {
        return R.menu.publish_circle_menu;
    }

    @Override
    protected void initToolBar() {
        initToolBar(toolbar, title);

        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.action_publish_package:
                        IntentUtils.startActivity(mContext, CreateCircleActivity.class);
                        break;
                    case R.id.action_friends:
                        IntentUtils.startActivity(mContext, FriendsCircleThemeActivity.class);
                        break;

                }
                return true;
            }
        });

//        listView.setAdapter(new TeamAdapter(mContext));


    }

    @Override
    protected void setUpViews() {

        tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
//        tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
        tabLayout.setVisibility(View.GONE);
        List<Fragment> tcf = new ArrayList<>();
//        tcf.add(new MyCircleFragment().newInstance(1));
        tcf.add(new MyCircleFragment().newInstance(0));
        IFragmentPagerAdapter pagerAdapter = new IFragmentPagerAdapter(getSupportFragmentManager(), tcf);
        pagerAdapter.setTitles(new String[]{"参与的圈子"});
        complaintViewpager.setAdapter(pagerAdapter);
        tabLayout.setupWithViewPager(complaintViewpager);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
    }

    @OnClick(R.id.send_message)
    public void goSearch(View view) {
        if (filterEdit.getText() != null && !TextUtils.isEmpty(filterEdit.getText().toString()))
            IntentUtils.startActivity(this, SearchCircleThemeActivity.class, "key", filterEdit.getText().toString());
    }

}